package springMVC.getParams.controller;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author quan
 * @Description 获取url中的参数
 * @Date 2023/7/22 16:11
 */
@RestController
@RequestMapping("/web")
public class Demo6_GetUrlParam {
    //接收一个参数shopId
    @RequestMapping("/get6/{shopId}")
    public String get6(@PathVariable Integer shopId){
        return "shopId:"+shopId;
    }
    //接收两个参数：shopId和goodsId
//    @RequestMapping("/get6/{shopId}/{goodsId}")
//    public String get6(@PathVariable Integer shopId,@PathVariable Integer goodsId){
//        return "shopId:"+shopId+"|goodsId"+goodsId;
//    }
//    //接收两个参数，但是将goodsId名字修改为GoodsId
//    @RequestMapping("/get6/{shopId}/{goodsId}")
//    public String get6(@PathVariable Integer shopId,@PathVariable(value = "goodsId") Integer GoodsId){
//        return "shopId:"+shopId+"|修改后的名称是"+GoodsId;
//    }
    //默认参数是必传的，如果不要必传，要设置为false(没成功？)
//    @RequestMapping("/get6/{shopId}/{goodsId}")
//    public String get6(@PathVariable(required = false) Integer shopId,@PathVariable(required = false) Integer goodsId){
//        return "shopId:"+shopId+"|修改后的名称是"+goodsId;
//    }
}
